﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using EHTWebsiteProject.Code.Entity;

namespace EHTWebsite.Code
{
    public class DanhMucKhachHangProvider
    {
        public static DataSet GetDanhMucKhachHangPaggin(DanhMucKhachhang theDanhMucKhachHang, Int32 pageIndex ,Int32 pageSize,out Int32 totalRecord)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_PaggingDanhMucKhachHang";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@DanhMucKhachHangID", theDanhMucKhachHang.DanhMucKhachHangID));
            command.Parameters.Add(new SqlParameter("@TenDanhMucKhachHangVN", theDanhMucKhachHang.TenDanhMucKhachHangVN));
            command.Parameters.Add(new SqlParameter("@TenDanhMucKhachHangOther", theDanhMucKhachHang.TenDanhMucKhachHangOther));
            command.Parameters.Add(new SqlParameter("@Publish", theDanhMucKhachHang.Publish));
            command.Parameters.Add(new SqlParameter("@NumberOfOrder", theDanhMucKhachHang.NumberOfOrder));
            command.Parameters.Add(new SqlParameter("@NhomDanhMucID", theDanhMucKhachHang.NhomDanhMucID));
            command.Parameters.Add(new SqlParameter("@PageIndex", pageIndex));
            command.Parameters.Add(new SqlParameter("@PageSize", pageSize));
            DataSet ds = DataProvider.ExecuteDataSet(command, out totalRecord);
            return ds;
        }

        public static DataSet GetDanhMucKhachHangByNhomID(Int32 NhomDanhMucID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetDanhMucKhachHang";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@NhomDanhMucID",NhomDanhMucID));
            return DataProvider.ExecuteDataSet(command);
        }

        public static void IUDanhMucKhachHangs(DanhMucKhachhang theDanhMucKhachHang, bool IsAdd)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_IUDanhMucKhachHangs";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@DanhMucKhachHangID",theDanhMucKhachHang.DanhMucKhachHangID));
            command.Parameters.Add(new SqlParameter("@TenDanhMucKhachHangVN",theDanhMucKhachHang.TenDanhMucKhachHangVN));
            command.Parameters.Add(new SqlParameter("@TenDanhMucKhachHangOther",theDanhMucKhachHang.TenDanhMucKhachHangOther));
            command.Parameters.Add(new SqlParameter("@Publish",theDanhMucKhachHang.Publish));
            command.Parameters.Add(new SqlParameter("@NumberOfOrder",theDanhMucKhachHang.NumberOfOrder));
            command.Parameters.Add(new SqlParameter("@NhomDanhMucID",theDanhMucKhachHang.NhomDanhMucID));
            command.Parameters.Add(new SqlParameter("@IsAdd",IsAdd));
            DataProvider.ExecuteNoneQuery(command);
        }

        public static DanhMucKhachhang GetDanhMucKhachHangByDanhMucID(Int32 DanhMucKhachHangID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetDanhMucKhachHangbyDanhMuc";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@DanhMucKhachHangID",DanhMucKhachHangID));
            DataSet ds = DataProvider.ExecuteDataSet(command);
            DanhMucKhachhang theDanhMucKhachHang = null;
            if (ds.Tables[0].Rows.Count > 0)
            {
                theDanhMucKhachHang = new DanhMucKhachhang();
                theDanhMucKhachHang.DanhMucKhachHangID = Int32.Parse(ds.Tables[0].Rows[0]["DanhMucKhachhangID"].ToString());
                theDanhMucKhachHang.TenDanhMucKhachHangVN = ds.Tables[0].Rows[0]["TenDanhMucKhachHangVN"].ToString();
                theDanhMucKhachHang.TenDanhMucKhachHangOther = ds.Tables[0].Rows[0]["TenDanhMucKhachHangOther"].ToString();
                theDanhMucKhachHang.Publish = Boolean.Parse(ds.Tables[0].Rows[0]["Publish"].ToString());
                theDanhMucKhachHang.NumberOfOrder = Int32.Parse(ds.Tables[0].Rows[0]["NumberOfOrder"].ToString());
                theDanhMucKhachHang.NhomDanhMucID = Int32.Parse(ds.Tables[0].Rows[0]["NhomDanhMucID"].ToString());
            }
            return theDanhMucKhachHang;
        }

        /// <summary>
        /// Author : toanvt
        /// CreatedDate : 10/02/2012
        /// Description : Lấy danh sách Danh Mục Khách Hàng
        /// </summary>
        /// <returns></returns>
        public static DataSet GetDanhMucKhachHangs()
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetDanhMucKhachHangs";
            command.CommandType = CommandType.StoredProcedure;
            DataSet ds = DataProvider.ExecuteDataSet(command);

            return ds;
        }

        public static DataSet DeleteDanhMucKhachHang(Int32 NhomDanhMucID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_DeleteDanhMucKhachHangs";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@NhomDanhMucID", NhomDanhMucID));
            return DataProvider.ExecuteDataSet(command);
        }

        public static DataSet UpdateNumberOfOrderByDanhMucKhachHangId(Int32 DanhMucKhachHangID, Int32 NumberOfOrder)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_UpdateNumberOfOrderbyDanhMucKhachHangId";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@DanhMucKhachHangID",DanhMucKhachHangID));
            command.Parameters.Add(new SqlParameter("@NumberOfOrder",NumberOfOrder));
            return DataProvider.ExecuteDataSet(command);
        }

        public static void ChangePublishByDanhMucKhachHangID(Int32 DanhMucKhachHangID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_ChangePublishByDanhMucKhachHangID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@DanhMucKhachHangID",DanhMucKhachHangID));
            DataProvider.ExecuteNoneQuery(command);
        }
    }
}